﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CloudClass.Models;
using Orchard.Data;

namespace CloudClass.Services
{
    public class MyCourseService : IMyCourseService
    {
        private readonly IRepository<MyCourse> _courseRepository;

        public MyCourseService(IRepository<MyCourse> courseRepository)
        {
            _courseRepository = courseRepository;
        }

        public virtual bool Create(Models.MyCourse model)
        {

            try
            {
                _courseRepository.Create(model);
            }
            catch
            {
                return false;
            }
            return true;
        }

        public virtual bool Edit(MyCourse model)
        {
            try
            {
                _courseRepository.Update(model);
            }
            catch
            {
                return false;
            }
            return true;
        }

        public virtual bool Delete(int[] array)
        {
            try
            {
                foreach (var id in array)
                {
                    var item = this.Get(id);
                    _courseRepository.Delete(item);
                }
            }
            catch
            {
                return false;
            }
            return true;
        }

        public virtual MyCourse Get(int id)
        {
            var item = _courseRepository.Get(id);
            return item;
        }

        public virtual List<MyCourse> GetList()
        {
            return _courseRepository.Table.ToList();
        }

        public virtual object List(out int count)
        {
            var list = _courseRepository.Table.ToList();
            count = list.Count;
            return list;
        }
    }
}